/*
* Copyright (c) 2016 ShopJsp. All Rights Reserved.
 * ============================================================================
 * 版权所有 2011 - 今 北京华宇盈通科技有限公司，并保留所有权利。
 * ----------------------------------------------------------------------------
 * 提示：在未取得SHOPJSP商业授权之前，您不能将本软件应用于商业用途，否则SHOPJSP将保留追究的权力。
 * ----------------------------------------------------------------------------
 * 官方网站：http://www.shopjsp.com
 * ============================================================================
*/
package com.hyyt.shopjsp.util.wxpay;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;

/**
 * 签名算法
 * @author JXW 
 * 2015/04/15
 */
public class Signature {

	public static String getSign(Map<String, Object> map) {
		ArrayList<String> list = new ArrayList<String>();
		for (Map.Entry<String, Object> entry : map.entrySet()) {
			if (entry.getValue() != "") {
				list.add(entry.getKey() + "=" + entry.getValue() + "&");
			}
		}
		int size = list.size();
		String[] arrayToSort = list.toArray(new String[size]);
		Arrays.sort(arrayToSort, String.CASE_INSENSITIVE_ORDER);
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < size; i++) {
			sb.append(arrayToSort[i]);
		}
		String result = sb.toString();
		//result += "key=odyk8xndqi9oaxov2bmi2ldcf6m7e5x3";// + WxPayConfigure.getKey();
		result += "key=" + WxPayConfigure.getKey();
//		System.out.println("WxPayConfigure.getKey()"+WxPayConfigure.getKey());
		result = MD5WeiXin.MD5Encode(result).toUpperCase();
		return result;
	}

}
